<?php
/*
 * Assetliability class for asset
 */

class Asset_Model_Assetliability extends WOW_Model_Acl_Abstract
{
    public function getResourceId()
    {
        return 'Assetliability';
    }

    public function saveAsset($post,$userid)
    {
        return $this->_save($post,$userid);
    }

    protected function _save(array $data,$userid)
    {
        if (count($data) == 0)
           return false;
                
        $data['catid'] = $data['hidden_cat_id'];
        $data['subcatid'] = $data['hidden_subcat_id'];
        $data['AssetCatLabelId'] = $data['hidden_label_id'];
        $data['user_id'] = $userid;
        $data['Type'] = 'A';
        $data['createdAt'] = date('Y-m-d H:i:s');
        return $this->getResource('Assetliability')->saveRow($data);
        
    }
    
    #@ TODO:: needs to be worked on ACL later
    public function setAcl(WOW_Acl_Interface $acl)
    {
        if (!$acl->has($this->getResourceId()))
        {
            $acl->add($this)->allow('Normal', $this, array('register'))
            ->allow('Moderator', $this, array('saveCategory'))
                    ->allow('Admin', $this);
        }
        $this->_acl = $acl;
        return $this;
    }

    public function getAcl()
    {
        if (null === $this->_acl) {
            $this->setAcl(new Main_Model_Acl_Main());
        }
        return $this->_acl;
    }
    
    public function getItemById($id)
    {
        $id = (int) $id;
        return $this->getResource('Assetliability')->getItemById($id);
    }
    
    
    public function deleteItem($assetId)
    {
        $item = $this->getItemById($assetId);

        if (null !== $item) {
            $item->delete();
            return true;
        }

        return false;
    }
    
}

?>
